package ezi

class Link implements Serializable{
  Link from
  String url
  int depth

  def Link(from, url, depth) {
    this.from = from;
    this.url = url;
    this.depth = depth
  }

  boolean equals(o) {
    if (this.is(o)) return true;
    if (getClass() != o.class) return false;

    Link link = (Link) o;
    println from?.url
    println link.from?.url

    if ((from?.url == link.from?.url && url == link.url) || (url == link.from?.url && from?.url == link.url)) return true;

    return false;
  }

  int hashCode() {
    int result;

    int first = (from != null ? from.url.hashCode() : 0);
    int last = (url != null ? url.hashCode() : 0);
    if (first < last) result = first * 31 + last
    else result = last * 31 + first
    return result;
  }

  String toString() {
    return "($depth) From: ${from?.url} =====> URL: $url"
  }
}